local RUtil = {}

--- 根据路径读取技能
---@param package Package
RUtil.loadSkillSkelsByPath = function(package)
  local path = "./packages/aaa_Romantic/pkg/"..package.name.."/skills"
  local skels = {}
  local normalized_dir = path
      :gsub("^%.+/", "")
      :gsub("/+$", "")
      :gsub("/", ".")
  for _, filename in ipairs(FileIO.ls(path)) do
    -- 别加载下划线开头的模板技能哈
    if filename:sub(-4) == ".lua" and filename ~= "init.lua" and not filename:startsWith("_") then
      local skel = Pcall(require, normalized_dir .. "." .. filename:sub(1, -5))
      if skel then
        -- 如果返回了一个skel表
        if type(skel) == "table" and skel[1] ~= nil then
          for _, v in ipairs(skel) do
            table.insert(skels, v)
          end
        else
          table.insert(skels, skel)
        end
      end
    end
  end
  package:loadSkillSkels(skels)
end

--- 加减谋略值
---@param room Room @ 房间
---@param player ServerPlayer @ 角色
---@param num integer @ 加减值，负为减
RUtil.handleMoulue = function(room, player, num)
  local n = player:getMark("@rmt_moulue") or 0
  local new_n = math.min(math.max(n + num, 0), 5)
  room:setPlayerMark(player, "@rmt_moulue", new_n)
  room:sendLog{
    type = num > 0 and "#addMoulue" or "#minusMoulue",
    from = player.id,
    arg = math.abs(num),
    arg2 = new_n,
  }
  room:handleAddLoseSkills(player, player:getMark("@rmt_moulue") > 0 and "rmt_miaoji" or "-rmt_miaoji", nil, false, true)
end

Fk:loadTranslationTable{
  ["@rmt_moulue"] = "谋略值",
  ["#addMoulue"] = "%from 加了 %arg 点谋略值，现在的谋略值为 %arg2 点",
  ["#minusMoulue"] = "%from 减了 %arg 点谋略值，现在的谋略值为 %arg2 点",
}

return RUtil
